package org.suyisen.feng.gateway.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

import reactor.core.publisher.Mono;

/**
 * 
 */
@Component
public class GatewayGlobalFilter implements GlobalFilter, Ordered{
	
	private static final Logger log = LoggerFactory.getLogger(GatewayGlobalFilter.class);

	@Override
	public int getOrder() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("=====================================网关过滤器执行=========================================");
        ServerHttpRequest request = exchange.getRequest();
        String requestUrl = request.getPath().value();
        log.info("请求URL：{}", requestUrl);
        HttpHeaders headers = request.getHeaders();
        String accessKey = headers.getFirst ("accessKey");
        String timestamp = headers.getFirst("timestamp");
        String random = headers.getFirst("random");
        String body = headers.getFirst("body");
        String sign = headers.getFirst("sign");
	     return chain.filter(exchange);
	}

}
